package com.s666.demo.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.s666.demo.dao.entity.TagPlus;
import com.s666.demo.dao.entity.Ziku;
import com.s666.demo.dao.mapper.TagPlusMapper;
import com.s666.demo.dao.mapper.ZikuMapper;
import com.s666.demo.service.TagPlusService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
/**
 * @author lijin
 */
@Service
public class TagPlusServiceImpl extends ServiceImpl<TagPlusMapper, TagPlus> implements TagPlusService {

    @Resource
    TagPlusMapper tagPlusMapper;

    @Override
    public Page<TagPlus> selectUserPage(int pageNum) {
        Page<TagPlus> pager = new Page<TagPlus>(pageNum, 10);

        List<TagPlus> tagPlusList = tagPlusMapper.selectPage(
                pager,
                new EntityWrapper<TagPlus>().orderBy("id",true)
        );
        return pager.setRecords( tagPlusList );
    }

    @Override
    public Integer countTags(){
        return tagPlusMapper.selectCount(new EntityWrapper<TagPlus>());
    }

    @Override
    public TagPlus insert(String name, Integer type){
        TagPlus tagPlus = new TagPlus();
        tagPlus.setName(name);
        tagPlus.setType(type);
        tagPlus.setVersion(0);
        boolean result = tagPlus.insert();
        if (!result){
            return null;
        }
        return tagPlus;
    }

}
